#!/usr/bin/python
import cgi, cgitb
import MySQLdb as mdb
import sys
form = cgi.FieldStorage()
name = form.getvalue('first_name')
con = mdb.connect('localhost', 'testuser', 'test123', 'testdb')
cur = con.cursor()
#cur.execute("SELECT * FROM Writers where name=%s", (name)) #where clause in python

  ## Safety pig has arrived!
  #text = h(text)
  ##                               _
  ##  _._ _..._ .-',     _.._(`))
  ## '-. `     '  /-._.-'    ',/
  ##    )         \            '.
  ##   / _    _    |             \
  ##  |  a    a    /              |
  ##  \   .-.                     ;  
  ##   '-('' ).-'       ,'       ;
  ##      '-;           |      .'
  ##         \           \    /
  ##         | 7  .__  _.-\   \
  ##         | |  |  ``/  /`  /
  ##        /,_|  |   /,_/   /
  ##           /,_/      '`-'
  ##


cur.execute("SELECT * FROM %s" % (name))
numrows = int(cur.rowcount)

print "Content-type:text/html\r\n\r\n"
for i in range(numrows):
	row = cur.fetchone()
	print '<table border = "1">'
	print '<tr>'
	print '<td>%s       </td>' % (row[0])
	print '<td>%s       </td>' % (row[1])
	print '</tr>'
	print '</table>'

con.close()
